#ifndef STEERNEWMETER_H
#define STEERNEWMETER_H

#include <QWidget>
#include <QPropertyAnimation>
#include <QPainter>
class SteerNewMeter : public QWidget
{
    Q_OBJECT

public:
    SteerNewMeter(QWidget *parent = nullptr);
    ~SteerNewMeter();

    enum ErrorCode {MaxValueError=1,MinValueError,ThresholdError,TargetError,PrecisionError,ColorError,UnitsEmpty,OutOfRange};

    double value() const { return m_value; }
    double minValue() const { return m_minValue; }
    double maxValue() const { return m_maxValue; }
    double threshold() const { return m_threshold; }
    double beginValidValue() const { return m_beginValidValue; }
    double endValidValue() const { return m_endValidValue; }
    double beginWarningValue() const { return m_beginWarningValue; }
    double endWarningValue() const { return m_endWarningValue; }
    int precision() const { return m_precision; }
    int precisionNumeric() const { return m_precisionNumeric; }
    QString units()const { return m_units; }
    QString label()const { return m_label; }
    int steps() const { return m_steps; }
    double startAngle() const { return m_startAngle; }
    double endAngle() const { return m_endAngle; }
    QColor foreground() const { return m_foreground; }
    QColor background() const { return m_background; }
    bool enableThreshold() const { return m_thresholdEnabled; }
    bool enableValidWindow() const { return m_enableValidWindow; }
    bool enableWarningWindow() const { return m_enableWarningWindow; }
    bool enableNumericIndicator() const { return m_numericIndicatorEnabled; }

    void customTextList(const QStringList &list);
    void setCustomTextList(const QStringList &customTextList);

    void setWindow(const QRect &rect);
    QString valueText() const;
    void setValueText(const QString &valueText);

signals:

    void errorSignal(int);
    void thresholdAlarm(bool);

public slots:

    void setValue(double);
    void setValue(int);
    void setMinValue(double);
    void setMinValue(int);
    void setMaxValue(double);
    void setMaxValue(int);
    void setThreshold(double);
    void setThreshold(int);
    void setPrecision(int);
    void setPrecisionNumeric(int);
    void setUnits(const QString &);
    void setLabel(const QString &);
    void setSteps(int);
    void setStartAngle(double);
    void setEndAngle(double);
    void setForeground(const QColor &);
    void setBackground(const QColor &);
    void setThresholdEnabled(bool);
    void setNumericIndicatorEnabled(bool);
    void setValueWithSpringEffect(int value);
    void setBeginValidValue(double);
    void setEndValidValue(double);
    void setEnableValidWindow(bool);
    void setBeginWarningValue(double);
    void setEndWarningValue(double);
    void setEnableWarningWindow(bool);

protected:

    double m_value = 0.0;
    QString _valueText;
    double m_maxValue = 0.0;
    double m_minValue = 0.0;
    int m_precision = 0;
    int m_precisionNumeric = 0;
    void thresholdManager();
    void paintEvent(QPaintEvent *event);
    void drawCrown(QPainter *painter);
    void drawBackground(QPainter *painter);
    void drawTicks(QPainter *painter);
    void drawScale(QPainter *painter);
    void drawUnits(QPainter *painter);
    void drawNeedle(QPainter *painter);
    void drawThresholdLine(QPainter *painter);
    void drawNumericValue(QPainter *painter);
    void drawCoverGlass(QPainter *painter);
    void drawLabel(QPainter *painter);
    void drawValidWindow(QPainter *painter);
    void drawWarningWindow(QPainter *painter);

    QString m_units;
    QString m_label;
    int m_steps = 0;
    double m_startAngle = 0.0;
    double m_endAngle  = 0.0;
    double m_threshold  = 0.0;
    bool m_thresholdFlag = false;
    bool m_enableValidWindow = false;
    double m_beginValidValue  = 0.0;
    double m_endValidValue  = 0.0;
    bool m_enableWarningWindow = false;
    double m_beginWarningValue  = 0.0;
    double m_endWarningValue  = 0.0;
    bool m_thresholdEnabled = false;
    bool m_numericIndicatorEnabled = false;
    QColor m_foreground;
    QColor m_background;
    QPropertyAnimation m_valAnimation;
    QStringList _customTextList;
    QRect _windowRect {-50,-50,100,100};
};
#endif // STEERNEWMETER_H
